/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package org.aroundme.unittests;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.aroundme.controller.ResponseController;
import org.aroundme.model.Place;
import org.aroundme.unitTools.TestFixture;
import org.aroundme.utility.Constants;
import org.springframework.mock.web.MockHttpServletResponse;

public class ResponseControllerTest extends TestFixture {
	private ResponseController responseController;
	private MockHttpServletResponse mockResponse;
	
	protected void setUp() throws Exception {
		super.setUp();
		responseController = (ResponseController) springFactory.getBean(ResponseController.class.getSimpleName());
		mockResponse = new MockHttpServletResponse();
		responseController.setResponse(mockResponse);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		responseController = null;
		mockResponse = null;
	}

	public void testSendAlert() throws UnsupportedEncodingException {
		String alertType = Constants.ALERT_ERROR;
		String message = "This is the Alert message!";
		
		responseController.sendAlert(alertType, message);
		
		String responseMsg = mockResponse.getContentAsString();
		assertTrue("contains the alertType", responseMsg.contains(alertType));
		assertTrue("contains the message", responseMsg.contains(message));
	}

	public void testSendPlaces() throws UnsupportedEncodingException {
		List<Place> places = xmlTestUtils.getDummyPlaces();
		
		responseController.sendPlaces(places);
		
		String responseMsg = mockResponse.getContentAsString();
		assertTrue("placeid's", responseMsg.contains("<id>" + places.get(0).getId() + "</id>") &&
								responseMsg.contains("<id>" + places.get(1).getId() + "</id>") &&
								responseMsg.contains("<id>" + places.get(0).getId() + "</id>"));
	}

}
